﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KD.Sms.UI_Sys
{
    public partial class frmUnattended : Form
    {
        public frmUnattended()
        {
            InitializeComponent();
        }


        private void tools_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
        {
            switch (e.Tool.Key)
            {
                case "Query":
                    DoBind();
                    break;
                case "Add":
                    frmUnattendedEdit obj = new frmUnattendedEdit();
                    obj.ShowDialog();
                    DoBind();
                    break;
            }
        }

        /// <summary>
        /// 无人值守加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmUnattended_Load(object sender, EventArgs e)
        {
            DoBind();
        }

        private void DoBind()
        {
            gridMain.DataSource = DAL.SqlLite.Main.Instance.DoQueryUnattendedList(txtCarNum.Text.Trim());

        }

        private void gridMain_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                if (gridMain.Columns[e.ColumnIndex].Name == "XG")
                {
                    gridMain.Rows[e.RowIndex].Cells["CarNum"].Value.ToString();
                    frmUnattendedEdit obj = new frmUnattendedEdit(gridMain.Rows[e.RowIndex]);
                    obj.ShowDialog();
                    DoBind();
                }

                if (gridMain.Columns[e.ColumnIndex].Name == "SC")
                {
                    var id = gridMain.Rows[e.RowIndex].Cells["CarNum"].Value.ToString();
                    DAL.SqlLite.Main.Instance.DoDeleteUnattended((id));
                    DoBind();
                }
            }
        }

        private void gridMain_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            gridMain.Rows[e.RowIndex].Cells["CarNum"].Value.ToString();
            frmUnattendedEdit obj = new frmUnattendedEdit(gridMain.Rows[e.RowIndex]);
            obj.ShowDialog();
            DoBind();
        }
    }
}
